<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
/*
    function compose(funcs) {
        console.log(funcs)
//        return funcs.reduceRight((composed, f) => f(composed));
        return funcs.reduce(function (composed, f) {
            console.log(composed)
            console.log(f)
            return composed
        });
    }

*/

/*
    var funs=[
        function () {
            return new Promise((resolve,reject) => {
                console.log("a")
                return resolve("a")
            });
        },
        function () {
            return new Promise((resolve,reject) => {
                console.log("b")
                return resolve("a")
            });
        },
        function () {
            return new Promise((resolve,reject) => {
                console.log("c")
                return resolve("c")
            });
        },
        function () {
            return new Promise((resolve,reject) => {
                console.log("d")
                return resolve("d")
            });
        },
    ]

    compose(funs)
    */

    /*function  as() {
        console.log("as")
        var varr=[]
        for(let x of oj) {
            varr.push(sa[x.type])
        }
        console.log(varr)
        return  function (val) {
            var pmis=[]
            var ob=varr[Symbol.iterator]()
            /!*console.log(ob)
             console.log(ob.next().value());
             console.log(ob.next().value());
             console.log(ob.next());*!/

            for(var x=0; x<varr.length;x++){
                let a=ob.next(3)
                if(!a.done){
                    setTimeout(function () {
                        a.value().then(function (res) {
                            console.log(res)
                            pmis.push(true)
                        }).catch(function (res) {
                            pmis.push(false)
                        })
                    },3000)

                }
            }
            console.log(pmis)

        }
    }*/

    var sa={
        required (val,next) {
            return new Promise((resolve,reject) => {
                let empty= "^\\s{0}$";
                console.log("required:"+new RegExp(empty).test(val))
                if(new RegExp(empty).test(val)){
                    return reject("失败")
                }else {
                    return resolve("成功")
                }
            });
        },
        username (val,next) {
            return new Promise((resolve,reject) => {
                let username= "^[A-Za-z0-9_\\-\\u4e00-\\u9fa5]+$";
                console.log("username:"+new RegExp(username).test(val))
                if(new RegExp(username).test(val)){
                    return resolve("成功")
                }else {
                    return reject("失败")
                }
            });
        },
        usernamepost(val){

        }
    }

    var oj=JSON.parse('[{ "type":"required", "message": "用户名不能为空" },{ "type":"username","message":"请填写正确的用户名"}]')

    async function dbFuc(oj,val) {

        for (let doc of oj) {
            console.log(doc.type)
            await sa[doc.type](val)


        }
        console.log("@@@@@@@@@@@@@@@@@@")
    }

    dbFuc(oj,"ssss")


   /* console.log(sa.required("1"))*/

    sa.required("").catch(function (res) {
        console.log(res)
    })

</script>

<script>
    var a="a"
    switch (a){
        case "a":
            console.log("a")
        case "b":
            console.log("b")
    }
</script>
</body>
</html>